import java.io.IOException;

import com.hp.hpl.jena.graph.Graph;
import com.hp.hpl.jena.graph.compose.MultiUnion;
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.tdb.TDB;
import com.hp.hpl.jena.tdb.TDBFactory;


public class TDBMerge {
	
	public static void main(String[] args) throws IOException {
		String[] tdbs = {"location", "organization", "person", "product", "technology"};
		String generalModelLocation = "tdb";
//		String storage = "C:\\home\\basti\\n-triples\\";
		Graph[] graphs = new Graph[tdbs.length];
		
		Dataset generalDs = TDBFactory.createDataset(generalModelLocation);
		Model generalModel = generalDs.getDefaultModel();
		
		//iterate over submodels
		for(int i=0;i<tdbs.length;i++) {
			System.out.println(tdbs[i]);
			Dataset ds = TDBFactory.createDataset(generalModelLocation + "/" + tdbs[i]);
			
			Model submodel = ds.getDefaultModel();
//			graphs[i] = submodel.getGraph();
//			add submodel to general model
			generalModel.add(submodel);
		}
		
		MultiUnion multiUnion = new MultiUnion(graphs);
		generalModel = ModelFactory.createModelForGraph(multiUnion);
		TDB.sync(generalModel);
	}
}
